From bd7abf0186b66ac2111f3050f2983ea3d59d643b Mon Sep 17 00:00:00 2001 From: robertlipe Date: Tue, 27 Jan 2015 02:31:38 +0000 Subject: [PATCH] Move global_opts.charset to QString. Tested: clang -fsanitize=address / testo on Mac. --- gpsbabel/cet_util.cc | 26 ++++++++++++-------------- gpsbabel/cet_util.h | 4 ++-- gpsbabel/defs.h | 2 +- gpsbabel/garmin.cc | 2 +- gpsbabel/main.cc | 3 +-- gpsbabel/xol.cc | 2 +- 6 files changed, 18 insertions(+), 21 deletions(-) diff --git a/gpsbabel/cet_util.cc b/gpsbabel/cet_util.cc index 3fb8ded52..d0157db84 100644 --- a/gpsbabel/cet_util.cc +++ b/gpsbabel/cet_util.cc @@ -23,6 +23,7 @@ #include "cet.h" #include "cet_util.h" #include // qsort +#include "src/core/logging.h" #include #include @@ -210,7 +211,7 @@ cet_register(void) } cet_cs_vec_t* -cet_find_cs_by_name(const char* name) +cet_find_cs_by_name(const QString& name) { int i, j; @@ -264,13 +265,13 @@ cet_deregister(void) /* gpsbabel additions */ int -cet_validate_cs(const char* cs, cet_cs_vec_t** vec, char** cs_name) +cet_validate_cs(const QString& cs, cet_cs_vec_t** vec, QString* cs_name) { cet_cs_vec_t* v; - if ((cs == NULL) || (strlen(cs) == 0)) { /* set default us-ascii */ + if (cs.isEmpty()) { /* set default us-ascii */ *vec = &cet_cs_vec_ansi_x3_4_1968; - *cs_name = xstrdup(CET_CHARSET_ASCII); + *cs_name = CET_CHARSET_ASCII; return 1; } @@ -280,7 +281,7 @@ cet_validate_cs(const char* cs, cet_cs_vec_t** vec, char** cs_name) *vec = v; return 1; } else { - *cs_name = NULL; + cs_name->clear(); *vec = NULL; return 0; } @@ -289,29 +290,26 @@ cet_validate_cs(const char* cs, cet_cs_vec_t** vec, char** cs_name) void cet_convert_deinit(void) { - if (global_opts.charset_name != NULL) { - xfree(global_opts.charset_name); - } global_opts.charset = NULL; - global_opts.charset_name = NULL; global_opts.codec = NULL; } void -cet_convert_init(const char* cs_name, const int force) +cet_convert_init(const QString& cs_name, const int force) { if ((force != 0) || (global_opts.charset == NULL)) { cet_convert_deinit(); if (0 == cet_validate_cs(cs_name, &global_opts.charset, &global_opts.charset_name)) { - fatal("Unsupported character set \"%s\"!\n", cs_name); + Fatal() << "Unsupported character set \"" << cs_name << "."; } - if ((cs_name == NULL) || (strlen(cs_name) == 0)) { /* set default us-ascii */ + if (cs_name.isEmpty()) { /* set default us-ascii */ global_opts.codec = QTextCodec::codecForName(CET_CHARSET_ASCII); } else { - global_opts.codec = QTextCodec::codecForName(cs_name); + QByteArray ba = CSTR(cs_name); + global_opts.codec = QTextCodec::codecForName(ba); } if (!global_opts.codec) { - fatal("Unsupported character set \"%s\"!\n", cs_name); + Fatal() << "Unsupported character set \"" << cs_name << "."; } } } diff --git a/gpsbabel/cet_util.h b/gpsbabel/cet_util.h index 925cdae51..fb08c6c80 100644 --- a/gpsbabel/cet_util.h +++ b/gpsbabel/cet_util.h @@ -28,7 +28,7 @@ #include "cet.h" -cet_cs_vec_t* cet_find_cs_by_name(const char* name); +cet_cs_vec_t* cet_find_cs_by_name(const QString& name); void cet_register(void); void cet_deregister(void); @@ -61,7 +61,7 @@ const char* cet_convert_string(const QString& str); /* gpsbabel extensions */ -void cet_convert_init(const char* cs_name, const int force); +void cet_convert_init(const QString& cs_name, const int force); void cet_convert_strings(const cet_cs_vec_t* source, const cet_cs_vec_t* target, const char* format); void cet_convert_deinit(void); diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 16ced996b..d0c72f8d2 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -193,7 +193,7 @@ typedef struct { int smart_icons; int smart_names; cet_cs_vec_t* charset; - char* charset_name; + QString charset_name; inifile_t* inifile; QTextCodec* codec; } global_options; diff --git a/gpsbabel/garmin.cc b/gpsbabel/garmin.cc index 5e9102851..2d2b9bf6b 100644 --- a/gpsbabel/garmin.cc +++ b/gpsbabel/garmin.cc @@ -279,7 +279,7 @@ rw_init(const char* fname) // them to sort our the wreckage of violating the Garmin protocol and // ship characters to the device in that character set. if (global_opts.charset != &cet_cs_vec_utf8) { - receiver_charset = global_opts.charset_name; + receiver_charset = xstrdup(global_opts.charset_name); } if (global_opts.debug_level > 0) { fprintf(stderr, "Waypoint type: %d\n" diff --git a/gpsbabel/main.cc b/gpsbabel/main.cc index 5d2b7ed60..6f0bc1737 100644 --- a/gpsbabel/main.cc +++ b/gpsbabel/main.cc @@ -279,8 +279,7 @@ main(int argc, char* argv[]) global_opts.objective = wptdata; global_opts.masked_objective = NOTHINGMASK; /* this makes the default mask behaviour slightly different */ - global_opts.charset = NULL; - global_opts.charset_name = NULL; + global_opts.charset_name.clear(); global_opts.inifile = NULL; gpsbabel_now = time(NULL); /* gpsbabel startup-time */ diff --git a/gpsbabel/xol.cc b/gpsbabel/xol.cc index 460380748..fb08e94c0 100644 --- a/gpsbabel/xol.cc +++ b/gpsbabel/xol.cc @@ -313,7 +313,7 @@ xol_write(void) gt_get_mps_grid_longname(grid_swiss, MYNAME)); } - gbfprintf(fout, "\n", global_opts.charset_name); + gbfprintf(fout, "\n", CSTR(global_opts.charset_name)); gbfprintf(fout, "\n"); gbfprintf(fout, "%*s\n", space++*2, ""); gbfprintf(fout, "%*s
\n", space*2, "", x, y); -- 2.30.2